﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.AssetManage;
using LJX.SmartPark.Domain.ParkManage;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static LJX.SmartPark.Service.AssetManage.EquipmentLedgerServeice;

namespace LJX.SmartPark.Service.ParkManage
{
    public class AlarmRecordService: IAlarmRecordService
    {
        private readonly IRepository<AlarmRecord> _AlarmRecordService;

        public AlarmRecordService(IRepository<AlarmRecord> AlarmRecordService)
        {
            _AlarmRecordService = AlarmRecordService;
        }

        /// <summary>
        /// 获取总条数
        /// </summary>
        /// <returns></returns>
        public int GetCount()
        {
            return _AlarmRecordService.GetCount();
        }

        /// <summary>
        /// 显示分页
        /// </summary>
        /// <param name="select"></param>
        /// <returns></returns>
        public async Task<Response<List<AlarmRecord>>> GetAlarmRecordPage(AlarmRecordSelect select)
        {
            var datas = await _AlarmRecordService.GetAllListAsync();
            var result = datas.MapToList<AlarmRecord>();

            if (!string.IsNullOrEmpty(select.equipmentName))
            {
                result = result.Where(a => a.EquipmentName.Contains(select.equipmentName)).ToList();
            }

            if (!string.IsNullOrEmpty(select.status))
            {
                result = result.Where(a => a.Status == bool.Parse(select.status)).ToList();
            }

            var totalCount = result.Count();

            result = result.Skip(((select.pageIndex - 1) * select.pageSize)).Take(select.pageSize).ToList();

            return Response<List<AlarmRecord>>.Ok(result, totalCount);
        }

        public class AlarmRecordSelect
        {
            public int pageIndex { get; set; }
            public int pageSize { get; set; }

            public string? equipmentName { get; set; }
            public string? status { get; set; }
        }
    }
}
